package com.mak001.lite.multiSkill.GUI;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;

import com.mak001.lite.multiSkill.MainLite;
import com.mak001.lite.multiSkill.subScript;
import com.mak001.lite.multiSkill.GUI.Tabs.AlcherTab;
import com.mak001.lite.multiSkill.GUI.Tabs.BoneBuryTab;
import com.mak001.lite.multiSkill.GUI.Tabs.ChopperTab;
import com.mak001.lite.multiSkill.GUI.Tabs.CookerTab;
import com.mak001.lite.multiSkill.GUI.Tabs.FireMakerTab;
import com.mak001.lite.multiSkill.GUI.Tabs.FisherTab;
import com.mak001.lite.multiSkill.GUI.Tabs.MinerTab;
import com.mak001.lite.multiSkill.GUI.Tabs.RCTab;
import com.mak001.lite.multiSkill.GUI.Tabs.SuperHeaterTab;
import com.mak001.lite.multiSkill.subs.AlcherLite;
import com.mak001.lite.multiSkill.subs.BoneBuryLite;
import com.mak001.lite.multiSkill.subs.CookerLite;
import com.mak001.lite.multiSkill.subs.FireMakerLite;
import com.mak001.lite.multiSkill.subs.PowerChopperLite;
import com.mak001.lite.multiSkill.subs.PowerFisherLite;
import com.mak001.lite.multiSkill.subs.RuneCrafterLite;
import com.mak001.lite.multiSkill.subs.SuperHeaterLite;
import com.mak001.lite.multiSkill.subs.Miners.Miner;
import com.mak001.lite.multiSkill.subs.Miners.RuneEssMiner;
import com.mak001.lite.multiSkill.subs.Miners.StairMiner;

public class GUILite extends JFrame {

	private static final long serialVersionUID = 1L;

	public GUILite() {
		initComponents();
	}

	ArrayList<subScript> temp = new ArrayList<subScript>();

	String[] trees = { "normal", "oak", "willow" };

	private void boneBuryActionPerformed(ActionEvent e) {
		if (boneBury.isSelected()) {
			tabbedPane1.add("Bone Bury", bonebury);
		} else {
			tabbedPane1.remove(bonebury);
		}
	}

	private void alcherActionPerformed(ActionEvent e) {
		if (alcher.isSelected()) {
			tabbedPane1.add("Alcher", alcherTab);
		} else {
			tabbedPane1.remove(alcherTab);
		}
	}

	private void superHeaterActionPerformed(ActionEvent e) {
		if (superHeater.isSelected()) {
			tabbedPane1.add("Super Heater", superheater);
		} else {
			tabbedPane1.remove(superheater);
		}
	}

	private void cookerActionPerformed(ActionEvent e) {
		if (cooker.isSelected()) {
			tabbedPane1.add("Cooker", cookerTab);
		} else {
			tabbedPane1.remove(cookerTab);
		}
	}

	private void fireMakerActionPerformed(ActionEvent e) {
		if (fireMaker.isSelected()) {
			tabbedPane1.add("Fire Maker", firemaker);
		} else {
			tabbedPane1.remove(firemaker);
		}
	}

	private void powerFisherActionPerformed(ActionEvent e) {
		if (powerFisher.isSelected()) {
			tabbedPane1.add("Fisher", powerfisher);
		} else {
			tabbedPane1.remove(powerfisher);
		}
	}

	private void powerMinerActionPerformed(ActionEvent e) {
		if (powerMiner.isSelected()) {
			tabbedPane1.add("Miner", MinerTab);
		} else {
			tabbedPane1.remove(MinerTab);
		}
	}

	private void powerChopperActionPerformed(ActionEvent e) {
		if (powerChopper.isSelected()) {
			tabbedPane1.add("Chopper", powerchopper);
		} else {
			tabbedPane1.remove(powerchopper);
		}
	}

	private void runeCrafterActionPerformed(ActionEvent e) {
		if (runeCrafter.isSelected()) {
			tabbedPane1.add("Rune Crafter", RCTab);
		} else {
			tabbedPane1.remove(RCTab);
		}
	}

	private void start(ActionEvent e) {
		if (boneBury.isSelected()) {
			MainLite.bb = new BoneBuryLite();
			MainLite.bb.setBone(bonebury.getBone(), bonebury.getBoneName());
			temp.add(MainLite.bb);
		}
		if (alcher.isSelected()) {
			MainLite.al = new AlcherLite();
			MainLite.al.setItem(alcherTab.getItem());
			temp.add(MainLite.al);
		}
		if (superHeater.isSelected()) {
			MainLite.sh = new SuperHeaterLite();
			MainLite.sh.setInf(superheater.getPrimary(), superheater
					.getSecondary(), superheater.getWithdraw(), superheater
					.getBarName());
			temp.add(MainLite.sh);
		}
		if (cooker.isSelected()) {
			MainLite.cl = new CookerLite();
			MainLite.cl.setInf(cookerTab.getRaw(), cookerTab.getLogs(),
					cookerTab.getFoodName());
			temp.add(MainLite.cl);
		}
		if (fireMaker.isSelected()) {
			MainLite.fm = new FireMakerLite();
			MainLite.fm.setLog(firemaker.getLogs(), firemaker.getLogName());
			temp.add(MainLite.fm);
		}
		if (powerFisher.isSelected()) {
			MainLite.fisher = new PowerFisherLite();
			MainLite.fisher.setInf(powerfisher.getGear(), powerfisher
					.getFishingSpots(), powerfisher.getFishingArea(),
					powerfisher.getDrop(), powerfisher.getStiles(), powerfisher
							.getInteract(), powerfisher.getFishName());
			temp.add(MainLite.fisher);
		}
		if (powerMiner.isSelected()) {
			if (MinerTab.getMiner() == 0) { // rune ess
				MainLite.rem = new RuneEssMiner();
				MainLite.rem.setPlace(MinerTab.getPlace());
				temp.add(MainLite.rem);
			} else if (MinerTab.getMiner() == 1) {// stair miner
				MainLite.sminer = new StairMiner();
				MainLite.sminer.setArea(MinerTab.getSPlace());
				MainLite.sminer.setRock(MinerTab.getRocks());
				temp.add(MainLite.sminer);
			} else if (MinerTab.getMiner() == 3) {// normal miner
				MainLite.miner = new Miner();
				MainLite.miner.setRock(MinerTab.getRocks());
				MainLite.miner.setMine(MinerTab.getMiningArea());
				MainLite.miner.setBanking(true);
				temp.add(MainLite.miner);
			} else if (MinerTab.getMiner() == 2) { // power miner
				MainLite.miner = new Miner();
				MainLite.miner.setRock(MinerTab.getRocks());
				MainLite.miner.setMine(MinerTab.getMiningArea());
				MainLite.miner.setBanking(false);
				temp.add(MainLite.miner);
			}
		}
		if (powerChopper.isSelected()) {
			MainLite.pc = new PowerChopperLite();
			MainLite.pc.setInf(powerchopper.getTrees(), powerchopper.getArea(),
					powerchopper.getTreeName(), powerchopper.getDrop());
			temp.add(MainLite.pc);
		}
		if (runeCrafter.isSelected()) {
			MainLite.rcer = new RuneCrafterLite();
			MainLite.rcer.setrune(RCTab.getRune());
			MainLite.rcer.setTally(RCTab.getTally());
			temp.add(MainLite.rcer);
		}
		if (shutDownT.isSelected()) {
			MainLite.shutDown = true;
		} else {
			MainLite.shutDown = false;
		}
		MainLite.setMinMax(minTime.getText(), maxTime.getText());
		java.util.Collections.shuffle(temp);
		addSub(temp);
		MainLite.start = true;
		// TODO add your code here
	}

	public static void addSub(ArrayList<subScript> s) {
		MainLite.subs = s;
	}

	private void initComponents() {
		tabbedPane1 = new JTabbedPane();
		panel1 = new JPanel();
		textField1 = new JTextField();
		textField2 = new JTextField();
		textField3 = new JTextField();
		minTime = new JTextField();
		maxTime = new JTextField();
		textField4 = new JTextField();
		scrollPane1 = new JScrollPane();
		panel7 = new JPanel();
		boneBury = new JCheckBox();
		alcher = new JCheckBox();
		superHeater = new JCheckBox();
		cooker = new JCheckBox();
		fireMaker = new JCheckBox();
		powerFisher = new JCheckBox();
		powerMiner = new JCheckBox();
		powerChopper = new JCheckBox();
		runeCrafter = new JCheckBox();
		button1 = new JButton();
		hSpacer1 = new JPanel(null);

		bonebury = new BoneBuryTab();
		alcherTab = new AlcherTab();
		superheater = new SuperHeaterTab();
		cookerTab = new CookerTab();
		firemaker = new FireMakerTab();
		MinerTab = new MinerTab();
		RCTab = new RCTab();
		powerfisher = new FisherTab();
		powerchopper = new ChopperTab();

		shutDownT = new JRadioButton();
		shutDownF = new JRadioButton();
		textPane1 = new JTextPane();

		// ======== this ========
		setResizable(false);
		setTitle("Lite");
		Container contentPane = getContentPane();
		contentPane.setLayout(new GridLayout());

		// ======== tabbedPane1 ========
		{

			// ======== panel1 ========
			{
				panel1.setLayout(null);

				// ---- textField1 ----
				textField1.setText("Minimum");
				textField1.setEditable(false);
				textField1.setHorizontalAlignment(SwingConstants.CENTER);
				panel1.add(textField1);
				textField1.setBounds(20, 40, 70,
						textField1.getPreferredSize().height);

				// ---- textField2 ----
				textField2.setText("Maximum");
				textField2.setEditable(false);
				textField2.setHorizontalAlignment(SwingConstants.CENTER);
				panel1.add(textField2);
				textField2.setBounds(95, 40, 75,
						textField2.getPreferredSize().height);

				// ---- textField3 ----
				textField3.setText("Time to spend on subScript");
				textField3.setEditable(false);
				textField3.setHorizontalAlignment(SwingConstants.CENTER);
				panel1.add(textField3);
				textField3.setBounds(20, 15, 150,
						textField3.getPreferredSize().height);

				// ---- minTime ----
				minTime.setText("Minimum");
				minTime.setHorizontalAlignment(SwingConstants.CENTER);
				panel1.add(minTime);
				minTime.setBounds(20, 65, 70, 20);

				// ---- maxTime ----
				maxTime.setText("Maximum");
				maxTime.setHorizontalAlignment(SwingConstants.CENTER);
				panel1.add(maxTime);
				maxTime.setBounds(95, 65, 75, 20);

				// ---- textField4 ----
				textField4.setText("subScript Selection");
				textField4.setHorizontalAlignment(SwingConstants.CENTER);
				textField4.setEditable(false);
				panel1.add(textField4);
				textField4.setBounds(200, 15, 175, textField4
						.getPreferredSize().height);

				// ======== scrollPane1 ========
				{

					// ======== panel7 ========
					{
						panel7.setLayout(null);

						// ---- boneBury ----
						boneBury.setText("Bone Bury");
						boneBury.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								boneBuryActionPerformed(e);
							}
						});
						panel7.add(boneBury);
						boneBury.setBounds(10, 5, 135, boneBury
								.getPreferredSize().height);

						// ---- alcher ----
						alcher.setText("Alcher");
						alcher.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								alcherActionPerformed(e);
							}
						});
						panel7.add(alcher);
						alcher.setBounds(10, 30, 135,
								alcher.getPreferredSize().height);

						// ---- superHeater ----
						superHeater.setText("Super Heater");
						superHeater.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								superHeaterActionPerformed(e);
							}
						});
						panel7.add(superHeater);
						superHeater.setBounds(10, 55, 135, superHeater
								.getPreferredSize().height);

						// ---- cooker ----
						cooker.setText("Cooker");
						cooker.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								cookerActionPerformed(e);
							}
						});
						panel7.add(cooker);
						cooker.setBounds(10, 80, 135,
								cooker.getPreferredSize().height);

						// ---- fireMaker ----
						fireMaker.setText("Fire Maker");
						fireMaker.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								fireMakerActionPerformed(e);
							}
						});
						panel7.add(fireMaker);
						fireMaker.setBounds(10, 105, 135, fireMaker
								.getPreferredSize().height);

						// ---- powerFisher ----
						powerFisher.setText("Fisher");
						powerFisher.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								powerFisherActionPerformed(e);
							}
						});
						panel7.add(powerFisher);
						powerFisher.setBounds(10, 130, 135, powerFisher
								.getPreferredSize().height);

						// ---- powerMiner ----
						powerMiner.setText("Miner");
						powerMiner.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								powerMinerActionPerformed(e);
							}
						});
						panel7.add(powerMiner);
						powerMiner.setBounds(10, 155, 135, powerMiner
								.getPreferredSize().height);

						// ---- powerChopper ----
						powerChopper.setText("Power Chopper");
						powerChopper.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								powerChopperActionPerformed(e);
							}
						});
						// TODO - panel7.add(powerChopper);
						powerChopper.setBounds(10, 180, 135, powerChopper
								.getPreferredSize().height);

						// ---- runeCrafter ----
						runeCrafter.setText("Rune Crafter");
						runeCrafter.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								runeCrafterActionPerformed(e);
							}
						});
						panel7.add(runeCrafter);
						runeCrafter.setBounds(10, 205, 135, runeCrafter
								.getPreferredSize().height);

						{ // compute preferred size
							Dimension preferredSize = new Dimension();
							for (int i = 0; i < panel7.getComponentCount(); i++) {
								Rectangle bounds = panel7.getComponent(i)
										.getBounds();
								preferredSize.width = Math.max(bounds.x
										+ bounds.width, preferredSize.width);
								preferredSize.height = Math.max(bounds.y
										+ bounds.height, preferredSize.height);
							}
							Insets insets = panel7.getInsets();
							preferredSize.width += insets.right;
							preferredSize.height += insets.bottom;
							panel7.setMinimumSize(preferredSize);
							panel7.setPreferredSize(preferredSize);
						}
					}
					scrollPane1.setViewportView(panel7);
				}
				panel1.add(scrollPane1);
				scrollPane1.setBounds(200, 40, 175, 155);

				// ---- button1 ----
				button1.setText("Start");
				button1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						start(e);
					}
				});
				panel1.add(button1);
				button1.setBounds(20, 215, 355, 45);
				panel1.add(hSpacer1);
				hSpacer1.setBounds(375, 230, 25,
						hSpacer1.getPreferredSize().height);

				// ---- textPane1 ----
				textPane1
						.setText("shut down when all subscripts have been done?");
				textPane1.setEditable(false);
				panel1.add(textPane1);
				textPane1.setBounds(20, 105, 170,// 40
						textPane1.getPreferredSize().height);

				// ---- shutDownT ----
				shutDownT.setText("Yes");
				panel1.add(shutDownT);
				shutDownT.setBounds(20, 145, 150,
						shutDownT.getPreferredSize().height);

				// ---- shutDownF ----
				shutDownF.setText("No");
				panel1.add(shutDownF);
				shutDownF.setBounds(20, 170, 150,
						shutDownF.getPreferredSize().height);

				{ // compute preferred size
					Dimension preferredSize = new Dimension();
					for (int i = 0; i < panel1.getComponentCount(); i++) {
						Rectangle bounds = panel1.getComponent(i).getBounds();
						preferredSize.width = Math.max(bounds.x + bounds.width,
								preferredSize.width);
						preferredSize.height = Math.max(bounds.y
								+ bounds.height, preferredSize.height);
					}
					Insets insets = panel1.getInsets();
					preferredSize.width += insets.right;
					preferredSize.height += insets.bottom;
					panel1.setMinimumSize(preferredSize);
					panel1.setPreferredSize(preferredSize);
				}
			}
			tabbedPane1.addTab("Main", panel1);

			// ---- shutdownGroup ----
			ButtonGroup shutdownGroup = new ButtonGroup();
			shutdownGroup.add(shutDownT);
			shutdownGroup.add(shutDownF);

		}
		contentPane.add(tabbedPane1);
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization
		// //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	// Generated using JFormDesigner Open Source Project license - unknown
	private JTabbedPane tabbedPane1;
	private JPanel panel1;
	private JTextField textField1;
	private JTextField textField2;
	private JTextField textField3;
	private JTextField minTime;
	private JTextField maxTime;
	private JTextField textField4;

	private JScrollPane scrollPane1;
	private JPanel panel7;
	private JCheckBox boneBury;
	private JCheckBox alcher;
	private JCheckBox superHeater;
	private JCheckBox cooker;
	private JCheckBox fireMaker;
	private JCheckBox powerFisher;
	private JCheckBox powerMiner;
	private JCheckBox powerChopper;
	private JCheckBox runeCrafter;
	private JButton button1;
	private JPanel hSpacer1;

	private BoneBuryTab bonebury;
	private AlcherTab alcherTab;
	private SuperHeaterTab superheater;
	private CookerTab cookerTab;
	private FireMakerTab firemaker;
	private MinerTab MinerTab;
	private RCTab RCTab;
	private FisherTab powerfisher;
	private ChopperTab powerchopper;

	private JRadioButton shutDownT;
	private JRadioButton shutDownF;
	private JTextPane textPane1;

}
